package com.sevencar.activity;



import com.example.lightble.CmdSend;
import com.example.lightble.R;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.Toast;

public class ColorBoardActivity extends Activity implements OnClickListener{

	 private CmdSend  mCmdSend;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.color_board_layout);
		mCmdSend=CmdSend.getInstance();
		
	  findViewById(R.id.id_color_board_beige).setOnClickListener(this);
	  findViewById(R.id.id_color_board_bisque).setOnClickListener(this);
	  findViewById(R.id.id_color_board_bluebtn).setOnClickListener(this);
	  findViewById(R.id.id_color_board_cyan).setOnClickListener(this);
	  findViewById(R.id.id_color_board_gold).setOnClickListener(this);
	  findViewById(R.id.id_color_board_greenbtn).setOnClickListener(this);
	  findViewById(R.id.id_color_board_pink).setOnClickListener(this);
	  findViewById(R.id.id_color_board_powderblue).setOnClickListener(this);
	  findViewById(R.id.id_color_board_redbtn).setOnClickListener(this);
	  findViewById(R.id.id_color_board_skyblue).setOnClickListener(this);
	  findViewById(R.id.id_color_board_violet).setOnClickListener(this);
	  findViewById(R.id.id_color_board_writebtn).setOnClickListener(this);
	  
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int temp;
		switch (v.getId()) {
			case R.id.id_color_board_beige:
				 temp=0xFF00FF;
				 sendColor(temp);
				break;
			case	R.id.id_color_board_bisque:
				 temp=0xFFE4C4;
				 sendColor(temp);
				break;
			case	R.id.id_color_board_cyan:
				 temp=0x00FFFF;
				 sendColor(temp);
				break;
			case 	R.id.id_color_board_gold:
				 temp=0xFFD700;
				 sendColor(temp);
				break;
			case 	R.id.id_color_board_pink: 
				 temp=0xD2B48C;
				 sendColor(temp);
				break;
			case 	R.id.id_color_board_powderblue: 
				 temp=0x556B2F;
				 sendColor(temp);
				break;
			case 	R.id.id_color_board_skyblue: 
				 temp=0x87CEEB;
				 sendColor(temp);
				break;
			case 	R.id.id_color_board_violet:
				 temp=0xEE82EE;
				 sendColor(temp);
				break;
			case R.id.id_color_board_redbtn:
				 temp=0xFF0000;
				 sendColor(temp);
				 break;
			case R.id.id_color_board_greenbtn:
				 temp=0x00FF00;
				sendColor(temp);
				break;
			case R.id.id_color_board_bluebtn:
				 temp=0x0000FF;
				sendColor(temp);
				break;
			case R.id.id_color_board_writebtn:
				 temp=0xFFFFFF;
				sendColor(temp);
				break;
		default:
			break;
		}
	}
	 private void sendColor(int color)
	 {
//		 		RGBTwoApplication.getInstance().mCurrentColor=color;
		 		
		 		SharedPreferences sp = getSharedPreferences("color", 0);
		 		Editor ed = sp.edit();
		 	    ed.putInt("currentcolor", color);
		 		ed.commit();
		 		
		 		
			    byte[] test=mCmdSend.getRGBCmdArray(color,color);
	    	    HomeFragment.mBLEServiceInstance.sendData(test); 
	 }
	
}
